﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Core;
using GrayParrot.Core.ServiceBus;

namespace GrayParrot.RabbitMQ
{
    /// <summary>
    /// Service bus message base class...
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    [DataContract(Namespace = "")]
    public class MessageBusBase<T> : MessageBusBase<T, byte[]> where T : class, new()
    {
        //[DataMember]
        //public T Body
        //{
        //    get 
        //    {
        //        if (m_body == null)
        //        {
        //            m_body = new T();
        //        }

        //        return m_body; 
        //    }
        //    set { m_body = value; }
        //}

        public MessageBusBase()
        {
            CorrelationID = Guid.NewGuid();
            MessageID = Guid.NewGuid();
            Timestamp = DateTime.Now;
            //Body = new T();
        }

        public MessageBusBase(string messageName)
		{
            CorrelationID = Guid.NewGuid();
            MessageID = Guid.NewGuid();
            MessageName = messageName;
            Timestamp = DateTime.Now;
            //Body = new T();
		}

        /// <summary>
        /// Convert To the ServiceBus BrokeredMessage object...
        /// </summary>
        /// <returns>a BrokeredMessage object if success, null otherwise</returns>
        public override byte[] ToMessage()
        {
            byte[] retValue = null;

            // case of delayed message...
            if (this.DelayedDate != default(DateTime))
            {
            }

            retValue = this.Serialize();

            return retValue;
        }

        public override byte[] ToMessage(string xmlObject)
        {
            byte[] retValue = null;

            // case of delayed message...
            if (this.DelayedDate != default(DateTime))
            {
            }

            retValue = this.Serialize();

            return retValue;
        }
    }
}
